function getCookie(key) {
    const arr = document.cookie.split("; ");
    for (var i = 0; i < arr.length; i++) {
        const a = arr[i].split('=');
        if (a[0] === key) {
            return a[1];
        }
    }
    return "";
}

// 增&改
function setCookie(key, val, ops = {}) {
    // 处理路径的默认值
    const p = ops.path ? ";path=" + ops.path : "";
    // 处理过期时间的默认值
    let e = "";
    if (ops.expires) {
        const d = new Date();
        d.setDate(d.getDate() + ops.expires);
        e = ";expires=" + d;
    }
    // 设置cookie
    document.cookie = `${key}=${val}${p}${e}`;
}
